$(() => {obj.init();});

let obj = {
    dataGrid: null,
    dom: {
        btn: {
            setRead: null,
            del: null
        }
    },
    init: function () {
        this.dom.btn.setRead = $('#bt_list_set_read');
        this.dom.btn.del = $('#bt_list_del');

        this.dataGrid = new xhDataGrid($('#list'), 'remind/getNotice');
        this.dataGrid.parseToolbar().init().activeBtn(this.dom.btn.setRead.add(this.dom.btn.del));

        this.listener();
    },
    listener: function () {
        //双击打开消息
        this.dataGrid.onDblClickRow = (rowIndex, rowData) => {
            this.funObj().viewNotice(rowIndex, rowData);
        };
        //标记已读
        this.dom.btn.setRead.click(() => {
            if (xhExtra.buttonDisabled(this.dom.btn.setRead)) {
                return false;
            }
            this.funObj().setNoticeRead();
        });
        //删除
        this.dom.btn.del.click(() => {
            if (xhExtra.buttonDisabled(this.dom.btn.del)) {
                return false;
            }
            this.funObj().delNotice();
        });
    },
    funObj: function () {
        return {
            viewNotice: (rowIndex, rowData) => {
                //联动首页消息
                window.top.msg.funObj().viewNotice(rowData.noticeId);
                //判断是否需要处理
                if (!rowData.isRead && !rowData.isScrap) {
                    this.dataGrid.command('updateRow', {
                        index: rowIndex,
                        row: {
                            title: $(rowData.title).css('font-weight', '')[0].outerHTML,
                        }
                    });
                }
            },
            setNoticeRead: () => {
                xhExtra.ajaxRequest(
                    'remind/setNoticeRead',
                    {noticeIds: this.dataGrid.getSelectValues('noticeId')},
                    {check: true, success: true, table: this.dataGrid},
                    (result) => {
                        //联动首页初始化
                        window.top.msg.funObj().initMsg();
                    }
                );
            },
            delNotice: () => {
                xhExtra.askChangeStatus(
                    'remind/delNotice',
                    {ids: this.dataGrid.getSelectValues('id')},
                    this.dataGrid,
                    '确认删除？',
                    (result) => {
                        //联动首页初始化
                        window.top.msg.funObj().initMsg();
                    }
                );
            }
        }
    }
};